# coding: utf-8
# @Author: cyl
# @File: 02times.py
# @Time: 2024/07/28 20:37:37
import time
from datetime import datetime, timedelta


# 学习链接: https://blog.csdn.net/weixin_54546190/article/details/120897108

print(time.localtime())

# 1
print(time.time())
# 一般给前端的时间戳 或者 自己计算并不是这么写的, 一般这么写: int(time.time() * 1000)
print(int(time.time() * 1000))

print(time.mktime(time.localtime()))

# 2
print(time.strftime("%Y-%m-%d %X", time.localtime()))
print(time.strftime("%Y-%m-%d %x", time.localtime()))

# 3
print(time.strptime('2011-05-05 16:37:06', '%Y-%m-%d %X'))

# 4
print("当前时间: ", datetime.now())

# 5 时间加减、时间加减
dt = datetime.now()
# 日期减一天
dt1 = dt + timedelta(days=-1)  # 昨天
dt2 = dt - timedelta(days=1)   # 昨天
dt3 = dt + timedelta(days=1)   # 明天
delta_obj = dt3-dt
print(type(delta_obj),delta_obj)   # <type 'datetime.timedelta'> 1 day, 0:00:00
print(delta_obj.days ,delta_obj.total_seconds())   # 1 86400.0
